import { RbacMenuType } from '@/datatypes/rbacMenu/data';
import { list } from '@/services';
import { rbacMenuUrl } from '@/urls';
import { useEffect, useState } from 'react';

export const useMenus = () => {
  const [menus, setMenus] = useState<any>([]);

  useEffect(() => {
    const fetchRolesData = async () => {
      const data: API.ListResult<RbacMenuType> = await list(rbacMenuUrl);
      const transformedData = data?.list?.map((item) => ({ name: item.name, key: item.id })) || [];

      setMenus(transformedData || []);
    };

    fetchRolesData().then();
  }, []);

  return menus;
};
